﻿using Arction.Wpf.BindableCharting.SeriesXY;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WPF_UI_Lightningchart.ViewModels;

namespace WPF_UI_Lightningchart.UserControls
{
    /// <summary>
    /// SeriesSettingsWindow.xaml 的交互逻辑
    /// </summary>
        public partial class SeriesSettingsWindow : Window
        {
            private readonly PointLineSeries _series;

            public SeriesSettingsWindow(PointLineSeries series)
            {
                InitializeComponent();
                _series = series;

                // 初始化控件显示当前的 LineColor 和 LineWidth
                ColorRectangle.Fill = new SolidColorBrush(_series.LineStyle.Color);
                LineWidthSlider.Value = _series.LineStyle.Width;
            }

            private void OnChangeColorButton_Click(object sender, RoutedEventArgs e)
            {
                var colorDialog = new ColorDialog();
                if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    ColorRectangle.Fill = new SolidColorBrush(Color.FromArgb(
                        colorDialog.Color.A, colorDialog.Color.R, colorDialog.Color.G, colorDialog.Color.B));
                }
            }

            private void OnApplyButton_Click(object sender, RoutedEventArgs e)
            {
                if (ColorRectangle.Fill is SolidColorBrush brush)
                {
                    _series.LineStyle.Color = brush.Color;
                }

                _series.LineStyle.Width = (float)LineWidthSlider.Value;
                this.DialogResult = true;
                this.Close();
            }

            private void OnCancelButton_Click(object sender, RoutedEventArgs e)
            {
                this.DialogResult = false;
                this.Close();
            }
        }
}
